package com.example.c5;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringEncoder;

import java.net.InetSocketAddress;

/**
 * @author Jonathan
 * 2021/5/30 0:13
 */
public class HelloClient {
    public static void main(String[] args) throws InterruptedException {
        InetSocketAddress remote = new InetSocketAddress("127.0.0.1", 8080);
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(new NioEventLoopGroup())
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<NioSocketChannel>() {
                    @Override
                    protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception {
                        nioSocketChannel.pipeline().addLast(new StringEncoder());
                    }
                })
                .connect(remote)
                .sync()
                .channel()
                .writeAndFlush("hello world."); //向服务器发送数据

    }
}
